<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <!--<div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="游戏名称">
              <j-dict-select-tag v-model="queryParam.name" placeholder="请选择"
                                 dictCode='sys_category where pid = "0",name,id'/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="比赛名称">
              <a-input placeholder="请输入比赛名称" v-model="queryParam.matchName"></a-input>
            </a-form-item>
          </a-col>
          &lt;!&ndash;<template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="比赛海报(eg:入门赛)">
                <a-input placeholder="请输入比赛海报(eg:入门赛)" v-model="queryParam.matchPoster"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="比赛列表图片">
                <a-input placeholder="请输入比赛列表图片" v-model="queryParam.matchPic"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="门票名称">
                <a-input placeholder="请输入门票名称" v-model="queryParam.ticket"></a-input>
              </a-form-item>
            </a-col>
            </template>&ndash;&gt;
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              &lt;!&ndash;<a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>&ndash;&gt;
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>-->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

      <!--<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <!--<a-button type="primary" icon="download" @click="handleExportXls('门票管理')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-button @click="batchGive" type="primary" icon="share-alt">赠送门票</a-button>
        <!--<a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="share-alt"/>
            赠送门票
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>-->
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <!--<div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>-->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <!--<span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>

          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
          <a-divider type="vertical"/>
          <router-link tag="a" target="_blank"
                       :to="{path:'/match',query:{nameId:record.id}}">赛事维护</router-link>
          &lt;!&ndash;<a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>&ndash;&gt;
        </span>-->

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <name-modal ref="modalForm" @ok="modalFormOk"></name-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import NameModal from './modules/NameModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { deleteAction, getAction,downFile,getFileAccessHttpUrl } from '@/api/manage'

  export default {
    name: 'NameList',
    mixins: [JeecgListMixin],
    components: {
      NameModal
    },
    data() {
      return {
        description: '门票管理管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: '游戏名称',
            align: 'center',
            dataIndex: 'name_dictText'
          },
          {
            title: '比赛名称',
            align: 'center',
            dataIndex: 'matchName'
          },
          /*{
            title: '比赛海报(eg:入门赛)',
            align: 'center',
            dataIndex: 'matchPoster'
          },
          {
            title: '比赛列表图片',
            align: 'center',
            dataIndex: 'matchPic'
          },*/
          {
            title: '门票名称',
            align: 'center',
            dataIndex: 'ticket'
          },
          /*{
            title: '排序',
            align: 'center',
            dataIndex: 'sort',
            sorter:true
          },*/
          {
            title: '价格',
            align: 'center',
            dataIndex: 'price',
            sorter:true
          },
          /*{
            title: '门票图片',
            align: 'center',
            dataIndex: 'ticketPic'
          },*/
          /*{
            title: '代理直推佣金（元）',
            align: 'center',
            dataIndex: 'extensionOne'
          },
          {
            title: '推广佣金（元）',
            align: 'center',
            dataIndex: 'extension'
          },
          {
            title: '代理佣金（元）',
            align: 'center',
            dataIndex: 'agent'
          },
          {
            title: '青铜佣金（元）',
            align: 'center',
            dataIndex: 'bronze'
          },
          {
            title: '白银佣金（元）',
            align: 'center',
            dataIndex: 'silver'
          },
          {
            title: '黄金佣金（元）',
            align: 'center',
            dataIndex: 'gold'
          },
          {
            title: '白金佣金（元）',
            align: 'center',
            dataIndex: 'platinum'
          },
          {
            title: '钻石佣金（元）',
            align: 'center',
            dataIndex: 'diamonds'
          },*/

          /*{
            title: '0:正常,1:删除',
            align: 'center',
            dataIndex: 'delflag'
          },
          {
            title: 'remark',
            align: 'center',
            dataIndex: 'remark'
          },
          {
            title: 'remark1',
            align: 'center',
            dataIndex: 'remark1'
          },
          {
            title: 'remark2',
            align: 'center',
            dataIndex: 'remark2'
          },
          {
            title: 'remark3',
            align: 'center',
            dataIndex: 'remark3'
          },
          {
            title: 'remark4',
            align: 'center',
            dataIndex: 'remark4'
          },
          {
            title: 'remark5',
            align: 'center',
            dataIndex: 'remark5'
          },
          {
            title: 'remark6',
            align: 'center',
            dataIndex: 'remark6'
          },
          {
            title: 'remark7',
            align: 'center',
            dataIndex: 'remark7'
          },
          {
            title: 'remark8',
            align: 'center',
            dataIndex: 'remark8'
          },
          {
            title: 'remark9',
            align: 'center',
            dataIndex: 'remark9'
          },
          {
            title: 'remark10',
            align: 'center',
            dataIndex: 'remark10'
          },*/
          /*{
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }*/
        ],
        url: {
          list: '/name/name/list',
          delete: '/name/name/delete',
          deleteBatch: '/name/name/deleteBatch',
          exportXlsUrl: 'name/name/exportXls',
          importExcelUrl: 'name/name/importExcel',
          giveTicket: 'name/name/giveTicket'
        }
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      batchGive: function () {
        if(!this.url.giveTicket){
          this.$message.error("请设置url.giveTicket属性!")
          return
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var ids = "";
          var userId = this.$route.query.userId;
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          var that = this;
          this.$confirm({
            title: "确认赠送",
            content: "是否赠送选中门票?",
            onOk: function () {
              that.loading = true;
              getAction(that.url.giveTicket, {ids: ids,userId:userId}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
        }
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>